package com.sub.controller;

import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sub.pojo.User;
import com.sub.service.IUserService;

@Controller
@RequestMapping(value = "/test")
public class TestController {

	@Resource
	private IUserService service;

	@RequestMapping(value = "/insert", method = { RequestMethod.GET })
	@ResponseBody
	public Object insert() {
		User user = new User();
		user.setAge(23);
		user.setPassword("123213");
		user.setUserName("wangkai");
		user.setUserNum(UUID.randomUUID().toString());
		if (!service.insert(user)) {
			return "no";
		}
		return "ok";
	}

	@RequestMapping(value = "/update", method = { RequestMethod.GET })
	@ResponseBody
	public Object update() {
		User user = new User();
		user.setUserName("wangkai111");
		user.setTableIndex("_0000");
		user.setUserNum("ed1b6f36-7a9f-4f41-9f28-648a98db6aae");
		if (!service.update(user)) {
			return "no";
		}
		return "ok";
	}

	@RequestMapping(value = "/delete", method = { RequestMethod.GET })
	@ResponseBody
	public Object delete() {
		User user = new User();
		user.setTableIndex("_0000");
		user.setUserNum("ed1b6f36-7a9f-4f41-9f28-648a98db6aae");
		if (!service.delete(user)) {
			return "no";
		}
		return "ok";
	}

	@RequestMapping(value = "/select", method = { RequestMethod.GET })
	@ResponseBody
	public Object select() {
		User user = new User();
		user.setTableIndex("_0000");
		user.setUserNum("ed1b6f36-7a9f-4f41-9f28-648a98db6aae");
		return service.select(user);
	}

}
